//
//  ViewController.swift
//  Sky
//
//  Created by 王会阳 on 2018/11/16.
//  Copyright © 2018 why. All rights reserved.
//

import UIKit
import SnapKit

class ViewController: UIViewController {

    var loadingFailedLabel: UILabel!
    var activityIndicatorView: UIActivityIndicatorView!
    
    
    
    
    lazy var oneBox = UIView()
    lazy var twoBox = UIView()
    
    var bigImageView: UIButton?
    var leftBtn: UIButton?
    var rightBtn: UIButton?
    var titlelabel: UILabel?
    var stateLabel: UILabel?
    var timeLabel: UILabel?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        
        
        view.backgroundColor = UIColor.red

        oneBox.backgroundColor = UIColor.yellow
        twoBox.backgroundColor = UIColor.green

        view.addSubview(oneBox)
        view.addSubview(twoBox)

        oneBox.snp.makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.width.equalTo(view)
            make.top.equalTo(view).offset(0)
            make.height.equalTo(view).dividedBy(2)
        }

        twoBox.snp.makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.width.equalTo(view)
            make.top.equalTo(oneBox.snp_bottomMargin).offset(0)
            make.bottom.equalTo(view).offset(0)
        }
        
        initSubViews()

        
        setupView()
        
        
        
        
    }
    
    
    private func setupView(){
        oneBox.isHidden = true
        loadingFailedLabel.isHidden = true
        activityIndicatorView.startAnimating()
        activityIndicatorView.hidesWhenStopped = true
        
    }
    
    
    
    
    func initSubViews(){
        bigImageView = UIButton()
        bigImageView?.setImage(UIImage(named: "taiyang"), for: .normal)
        oneBox.addSubview(bigImageView!)
        
        bigImageView?.snp.makeConstraints({ (make) in
            make.size.equalTo(CGSize(width: 140, height: 140))
            make.top.equalTo(oneBox).offset(104)
            make.centerX.equalToSuperview()
        })
        
        leftBtn = UIButton(type: .infoDark)
        oneBox.addSubview(leftBtn!)
        
        leftBtn?.snp.makeConstraints({ (make) in
            make.size.equalTo(CGSize(width: 44, height: 44))
            make.left.equalToSuperview().offset(8)
            make.top.equalToSuperview().offset(64)
        })
        
        rightBtn = UIButton(type: .infoDark)
        oneBox.addSubview(rightBtn!)
        
        rightBtn?.snp.makeConstraints({ (make) in
            make.size.equalTo(CGSize(width: 44, height: 44))
            make.right.equalToSuperview().offset(8)
            make.top.equalToSuperview().offset(64)
        })
        
        titlelabel = UILabel()
        titlelabel?.text = "Beijing"
        titlelabel?.textColor = UIColor.red
        titlelabel?.textAlignment = .center
        titlelabel?.font = UIFont.systemFont(ofSize: 14)
        titlelabel?.sizeToFit()
        oneBox.addSubview(titlelabel!)
        
        titlelabel?.snp.makeConstraints({ (make) in
            make.left.equalTo((leftBtn?.snp.right)!)
            make.right.equalTo((rightBtn?.snp.left)!)
            make.top.equalTo(64)
            make.height.equalTo(44)
        })
        
        stateLabel = UILabel()
        stateLabel?.text = "clear"
        stateLabel?.textColor = UIColor.black
        stateLabel?.font = UIFont.systemFont(ofSize: 18)
        stateLabel?.sizeToFit()
        oneBox.addSubview(stateLabel!)
        
        stateLabel?.snp.makeConstraints({ (make) in
            make.centerX.equalTo(bigImageView!.snp.centerX)
            make.top.equalTo(bigImageView!.snp.bottom)
        })
        
        timeLabel = UILabel()
        timeLabel?.text = "Mon,25 September"
        timeLabel?.textColor = #colorLiteral(red: 0.9254902005, green: 0.2352941185, blue: 0.1019607857, alpha: 1)
        timeLabel?.font = UIFont.boldSystemFont(ofSize: 18)
        timeLabel?.sizeToFit()
        
        oneBox.addSubview(timeLabel!)
        
        timeLabel?.snp.makeConstraints({ (make) in
            make.top.equalTo(stateLabel!.snp.bottom)
            make.centerX.equalTo(stateLabel!.snp.centerX)
        })
        
        
        
    }
    


}

